home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap10
/
b10d010.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
3KB
|
70 lines
0, So, in this demonstration, I'll continue
3, working with text files. This time,
5, we'll be creating a text editor program.
7, And we'll use a text box object and the
10, common dialog object. Now I'm running the
12, program now and I can start off by just
14, typing some text. And I can use a
20, feature in my program that will sort of time
24, and date stamp it. And I can go ahead and
27, do that in the window. And then I can
31, move along and hit the Save As command,
34, and that will bring up a Save As dialog
36, box. That's a common dialog at work
39, there. And I can assign a text file name.
44, We'll call this Test2.txt. And my file
52, is saved to disk. So that's the basic
55, features of the text editing program. If
57, I wanted to type multiple lines, there'd
59, be no problem. I have scroll bars here
61, and that would scroll to quite some
62, distance down. I can exit the program by
66, clicking the Exit command. So as that closes,
70, let's take a quick look at some of the
71, program code. Really, the most important
74, event procedure in this program is the
77, mnuSaveItem event procedure, and that is
80, going to save the file to disk. Now, the
84, entire file is stored in Text property
88, of the text box object. And I create the
91, file just by appending lines to that text
96, box object. All right, so it's a pretty
98, simple procedure to save it. First, I'll
100, set my filter for the Save dialog box
103, because I want to show text files and then
106, I want to go ahead and display that
107, Save dialog box with the ShowSave method of
110, the common dialog object. Now, the user
113, has a chance to pick a file name. And
116, if they just hit OK and don't specify a
119, name, that would be blank. We have to be
122, careful about that because we'd be
124, trying to save to a file that we didn't
126, specify. So we want to test that with an If
130, statement. But if the file name is not
132, blank, then we want to open the file with
135, the Open command. An we'll open it for
137, output this time, rather than for input.
140, We're writing to disk. And we'll use the
142, Print statement to print the file to
147, the Open filenumber. And what we're
150, printing is, of course, the contents of our
152, text box object. And immediately after
155, that, we'll go ahead and close that file.
158, And our saving operation is complete.The
162, last thing I might show you is how that
163, nifty little date stamp worked. That's a
168, very simple procedure. I create a wrap
171, character, which will add a carriage
173, return to the text box. And then, I assign
177, the Date command and the wrap character
182, to the Text property of the text box
185, object. And so that just sort of puts it at
188, the very beginning of the text box
190, object, which is a quick way to stamp
193, something, maybe in a diary or something like
195, that. So, we've sort of rounded out
197, looking at text boxes here. We've seen how
200, to display them and now we're seeing how
204, to save text files to disk.
209, END